<?php 
/**
 * ERROR CODE 1020-1039
 *
 * */
class ADMIN_tables {
	private $error;
	private $user;
	public function __construct() {
		$this->error = $GLOBALS['error'];
		$this->user = new ADMIN_user();
	}
	public function tableStatusChange($tableID,$status) {
		if( !$this->user->checkUser() ) {
			$this->error->setError(1020,"not logined user");
			return false;
		}
		$objectID = $this->user->objrctID();
		if( $objectID == -1 ) {
			$this->error->setError(1021,"not object id in user");
			return false;
		}
		$db = new DB();
		$status = (int)$status;
		$status = ($status==0) ? 0 : 1;
		$tableID = (int)$tableID;
		$sql = "UPDATE `օbject_table` SET `օbject_table`.`status` = {$status}, `օbject_table`.`date_time` = CONCAT(CURDATE(),' ',CURTIME()) WHERE `id` = {$tableID} AND `object_id` = {$objectID}";
		$res = $db->query($sql);
		if( $res === false ) {
			return false;
		}
		$actionID = ($status == 1) ? 1 : 2;
		$actionName = ($status == 1) ? "start" : "stop";
		$sql = "INSERT INTO `օbject_table_history` ( `օbject_table_id`, `date_time`, `action_id`,`action_name` )
		VALUES ( '{$tableID}', CONCAT(CURDATE(),' ',CURTIME()), '{$actionID}', '{$actionName}' )";
		$res = $db->query($sql);
		if( $res === false ) {
			return false;
		}
		return true;
	}
	function rjt(){
		return true;
	}
	
}


?>